package org.germinus.telcoblocks.configuration;

import java.util.Properties;
import java.io.*;

public class AsteriskConfiguration
 {
  protected static String nl;
  public static synchronized AsteriskConfiguration create(String lineSeparator)
  {
    nl = lineSeparator;
    AsteriskConfiguration result = new AsteriskConfiguration();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "[general]" + NL + "context=internal" + NL + "usercallerid=";
  protected final String TEXT_2 = NL + "bindport=";
  protected final String TEXT_3 = NL + "bindaddr=";
  protected final String TEXT_4 = NL + "srvlookup=yes" + NL + "realm=";
  protected final String TEXT_5 = NL + NL + "disallow=all" + NL + "allow=ulaw                      \t\t\t\t\t\t\t\t\t" + NL + "allow=ilbc                      " + NL + "allow=alaw" + NL + ";allow=speex" + NL + ";allow=gsm" + NL + ";allow=h261" + NL + ";allow=h263" + NL + ";allow=h263p" + NL + ";allow=ulaw" + NL + ";allow=alaw" + NL + "" + NL + ";#trustrpid=yes" + NL + ";#sendrpid=yes" + NL + "subscribecontext=internal" + NL + "" + NL + "domain=";
  protected final String TEXT_6 = NL + NL + "videosupport=";
  protected final String TEXT_7 = NL + "externrefresh=";
  protected final String TEXT_8 = NL + NL + "localnet=192.168.0.0/255.255.0.0" + NL + "localnet=10.0.0.0/255.0.0.0" + NL + "localnet=172.16.0.0/12" + NL + "localnet=169.254.0.0/255.255.0.0" + NL + "" + NL + "lookup=yes" + NL + "" + NL + ";checkmwi=10";

 String entidad ="";
 
public void generateFile(File ficheroOrigen, File ficheroDestino) throws Exception {
	PrintWriter pw = new PrintWriter(new FileWriter(ficheroDestino));
	pw.print(generate(ficheroOrigen));
	pw.close();
}

/* (non-javadoc)
    * @see IGenerator#generate(Object)
    */
public String generate(File ficheroOrigen) throws Exception
  {
    final StringBuffer stringBuffer = new StringBuffer();
    XMLParser xp = new XMLParser();
    String entidad = "Centralita_VOIP";
    Properties propiedades = new Properties();
    propiedades = xp.read(ficheroOrigen, entidad);
    stringBuffer.append(TEXT_1);
    stringBuffer.append(propiedades.getProperty("usercallerid","yes"));
    stringBuffer.append(TEXT_2);
    stringBuffer.append(propiedades.getProperty("bindport","5060"));
    stringBuffer.append(TEXT_3);
    stringBuffer.append(propiedades.getProperty("binaddr","0.0.0.0"));
    stringBuffer.append(TEXT_4);
    stringBuffer.append(propiedades.getProperty("IP","127.0.0.1"));
    stringBuffer.append(TEXT_5);
    stringBuffer.append(propiedades.getProperty("domain","gsi.dit.upm.es"));
    stringBuffer.append(TEXT_6);
    stringBuffer.append(propiedades.getProperty("videosupport","yes"));
    stringBuffer.append(TEXT_7);
    stringBuffer.append(propiedades.getProperty("externrefresh","10"));
    stringBuffer.append(TEXT_8);
    return stringBuffer.toString();
  }
}
